<!--
 * @Author: your name
 * @Date: 2021-08-17 08:51:22
 * @LastEditTime: 2021-08-29 19:49:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \宏烨找房\client-applet\src\views\Home\index.vue
-->
<!--  -->
<template>
  <div class="home">
    <div class="homemain">
      <div class="swiper">
        <div class="am-flexbox">
          <div class="SearchHeader">
            <div class="location">
              <router-link to="/city">
                <input
                  type="text"
                  v-model="shghgd"
                  placeholder="上海"
                  class="int"
                  @click="iii"
                />
                <i class="el-icon-caret-bottom"></i>
              </router-link>
            </div>
            <div class="searchForm">
              <van-icon name="search" />
              <router-link to="/search">
                <span>请输入小区或地址</span>
              </router-link>
            </div>
          </div>
          <router-link to="/map">
            <i class="el-icon-map-location"></i>
          </router-link>
        </div>
        <van-swipe :autoplay="3000">
          <van-swipe-item
            v-for="(image, index) in images"
            :key="index"
            @click="onChange(image.id)"
          >
            <img :src="`http://47.102.145.189:8009` + image.imgSrc" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="flexbox-nav">
        <div class="am-flexbox-item">
          <router-link to="/findaroom">
            <img src="../../image/a1.png" alt="" />
            <p>整租</p>
          </router-link>
        </div>

        <div class="am-flexbox-item">
          <router-link to="/findaroom">
            <img src="../../image/a2.png" alt="" />
            <p>合租</p>
          </router-link>
        </div>
        <div class="am-flexbox-item">
          <router-link to="/map">
            <img src="../../image/a3.png" alt="" />
            <p>地图找房</p>
          </router-link>
        </div>
        <div class="am-flexbox-item">
          <router-link to="/lease">
            <img src="../../image/a4.png" alt="" />
            <p>去出租</p>
          </router-link>
        </div>
      </div>
      <div class="groups">
        <div class="groups-title">
          <h3>租房小组</h3>
          <span>更多</span>
        </div>
        <div class="am-grid">
          <div
            class="am-grid-item"
            v-for="(item, index) in list"
            :key="(item, index)"
          >
            <div class="desc">
              <h3>{{ item.title }}</h3>
              <p>{{ item.desc }}</p>
            </div>
            <img :src="`http://47.102.145.189:8009` + item.imgSrc" alt="" />
          </div>
        </div>
      </div>
      <div class="news">
        <h3 class="group-title">最新资讯</h3>
        <div class="am-wingblank">
          <div
            class="news-item"
            v-for="(news, index) in news"
            :key="(news, index)"
          >
            <div class="imgwrap">
              <img :src="`http://47.102.145.189:8009` + news.imgSrc" alt="" />
            </div>
            <div class="flexbox-align-center">
              <h3 class="title">{{ news.title }}</h3>
              <div class="justify">
                <span>{{ news.from }}</span>
                <span>{{ news.date }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import Vue from "vue";
import { Lazyload } from "vant";

Vue.use(Lazyload);
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      images: [],
      list: [],
      news: [],
      shghgd: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    onChange(index) {
      console.log("当前 id 索引：" + index);
      this.$router.push(`/detail/${index}`);
    },
    sdjhvgh() {
      this.shghgd = window.localStorage.getItem("label");
      console.log(this.shghgd);
    },
    iii() {
      this.$router.push("/map");
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    axios.get("http://47.102.145.189:8009/home/swiper").then((res) => {
      // console.log(res.data.body);
      this.images = res.data.body;
    });
    axios.get("http://47.102.145.189:8009/home/groups").then((res) => {
      // console.log(res.data.body);
      this.list = res.data.body;
    });
    axios.get("http://47.102.145.189:8009/home/news").then((res) => {
      // console.log(res.data.body);
      this.news = res.data.body;
    });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
};
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  .homemain {
    flex: 1;
    overflow-y: auto;
    .swiper {
      position: relative;
      height: 212px;
      .am-flexbox {
        text-align: left;
        overflow: hidden;
        display: flex;
        align-items: center;
        position: absolute;
        top: 25px;
        z-index: 1;
        width: 100%;
        padding: 0 10px;
        .el-icon-map-location {
          font-size: 25px;
          color: #fff;
        }
        .SearchHeader {
          text-align: left;
          overflow: hidden;
          display: flex;
          align-items: center;
          flex: 1 1;
          height: 34px;
          padding: 5px 5px 5px 8px;
          margin: 0 10px;
          border-radius: 3px;
          background-color: #fff;
          .location {
            .int {
              font-size: 14px;
              border: none;
              width: 30px;
            }
            .el-icon-caret-bottom {
              margin-left: 2px;
              font-size: 12px;
              color: #7f7f80;
            }
          }
          .searchForm {
            margin-left: 12px;
            border-left: 1px solid #ccc;
            display: flex;
            flex: 1 1;
            align-items: center;
            .van-icon {
              vertical-align: middle;
              padding: 0 2px 0 12px;
              color: #9c9fa1;
              font-size: 15px;
            }
            span {
              padding-left: 4px;
              font-size: 13px;
              color: #9c9fa1;
            }
          }
        }
      }
      .van-swipe {
        height: 212px;
        img {
          width: 100%;
          height: 212px;
        }
      }
    }
    .flexbox-nav {
      overflow: hidden;
      display: flex;
      padding: 10px 0;
      text-align: center;
      align-items: center;
      justify-content: space-around;
      .am-flexbox-item {
        img {
          width: 48px;
        }
        p {
          color: #000;
        }
      }
    }
    .groups {
      overflow: hidden;
      padding: 0 10px;
      background-color: #f6f5f6;
      .groups-title {
        display: flex;
        margin: 15px 0 15px 10px;
        justify-content: space-between;
        overflow: hidden;
        text-align: left;
      }
      .am-grid {
        width: 100%;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        margin: 10px 0;
        .am-grid-item {
          width: 48%;
          height: 85px;
          align-items: center;
          display: flex;
          background: #fff;
          justify-content: space-around;
          margin: 10px 0 0 5px;
          .desc {
            h3 {
              margin-bottom: 5px;
              font-size: 13px;
            }
            p {
              color: #999;
              font-size: 12px;
            }
          }
          img {
            width: 55px;
            height: 53px;
          }
        }
      }
    }
    .news {
      padding: 10px;
      background-color: #fff;
      overflow: hidden;
      .group-title {
        margin: 10px 0 5px 10px;
        font-size: 15px;
      }
      .am-wingblank {
        margin-left: 8px;
        margin-right: 8px;
        .news-item {
          display: flex;
          height: 120px;
          padding: 15px 10px 15px 0;
          border-bottom: 1px solid #e5e5e5;
          .imgwrap {
            width: 120px;
            height: 90px;
            img {
              width: 120px;
              height: 90px;
            }
          }
          .flexbox-align-center {
            height: 100%;
            padding-left: 12px;
            justify-content: space-between;
            flex-direction: column;
            text-align: left;
            overflow: hidden;
            display: flex;
            align-items: center;
            .title {
              margin-bottom: 15px;
              font-size: 14px;
            }
            .justify {
              width: 100%;
              color: #9c9fa1;
              font-size: 12px;
              text-align: left;
              overflow: hidden;
              display: flex;
              align-items: center;
              justify-content: space-between;
            }
          }
        }
      }
    }
  }
}
</style>
